'''
A tool for manually triggering the pump.

Created on 16.03.2013

@author: B. Wilbertz
'''

import sys, time, logging
import PyCoi
import RPi.GPIO as GPIO
from PyCoiGlobals import *


if __name__ == '__main__':
    pass

logging.basicConfig(level=logging.INFO)
        
nPumpStrokes = 50;

for arg in sys.argv[1:]:
    if ( int(arg) > 0 ): 
        nPumpStrokes = min(nPumpStrokes, int(arg))
    break

PyCoi.overrideGPIOWiring()
PyCoi.setupGPIO()

print "Pumping at most " + str(nPumpStrokes) + " times."
print
print

for i in range(nPumpStrokes):
    print("Pumping now!")
    try:
        GPIO.output(pins.pump, GPIO.HIGH)
        time.sleep(pumpTime)
    except Exception,e: 
        logging.error("Exception while pumping:" + str(e))
    finally:
        GPIO.output(pins.pump, GPIO.LOW)

    # we wait a bit to allow the pump to cool down
    time.sleep(pumpCoolDownTime)

    x = raw_input("Press enter to continue...")


GPIO.cleanup()